<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.Time" %>

<jsp:useBean id="addDiscount" class="se2.DiscountPlan" scope="request"/>
<jsp:setProperty name="addDiscount" property="*"/>
	
<%
	System.out.println(request.getParameter("startDay"));
	System.out.println(request.getParameter("startHour"));
	System.out.println(request.getParameter("startMinute"));

	String startDay = request.getParameter("startDay");
	int startHour = Integer.parseInt(request.getParameter("startHour"));
	int startMinute = Integer.parseInt(request.getParameter("startMinute"));
	
	String sHour = "" + startHour;
	if (startHour < 10)
	{
		sHour = "0" + startHour;
	}
	
	String sMinute = "" + startMinute;
	if (startMinute < 10)
	{
		sMinute = "0" + startMinute;
	}
	
	Time start = Time.valueOf (sHour + ":" + sMinute + ":00");
	
	String endDay = request.getParameter("endDay");
	int endHour = Integer.parseInt(request.getParameter("endHour"));
	int endMinute = Integer.parseInt(request.getParameter("endMinute"));
	
	String eHour = "" + endHour;
	if (endHour < 10)
	{
		eHour = "0" + endHour;
	}
	
	String eMinute = "" + endMinute;
	if (endMinute < 10)
	{
		eMinute = "0" + endMinute;
	}
	
	Time end = Time.valueOf (eHour + ":" + eMinute + ":00");
	
	addDiscount.setStartDay(startDay);
	addDiscount.setStartTime(start);
	addDiscount.setEndDay(endDay);
	addDiscount.setEndTime(end);

	if (addDiscount.addDiscountPlan())
	{
		System.out.println("Successfully created DiscountPlan.");
%>
		<jsp:forward page="viewDiscountPlan.jsp" />
<%
	}
	
	else
	{
		System.out.println("Fail in creating DiscountPlan.");
%>
		<jsp:forward page="error.jsp?url=addDiscountPlan.jsp" />
<%
	}	
%>

